<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="${ctx}/static/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="${ctx}/static/jqweui/css/weui.css">
    <link rel="stylesheet" href="${ctx}/static/jqweui/css/jquery-weui.css">
    <link rel="stylesheet" href="${ctx}/static/jqweui/css/icard.css?v=${cssVersion}">
    <link rel="stylesheet" href="${ctx}/static/font-awesome-4.7.0/css/font-awesome.css">

    <title>新增访客预约</title>

    <style>
        .weui-dialog.weui-dialog--visible{
            width: 90%;
            max-width: 500px;
        }

        .weui-media-box:before{
            display: none;
        }
        .weui-media-box:after{
            content: " ";
            position: absolute;
            left: 0;
            bottom: 0;
            right: 0;
            height: 1px;
            border-top: 1px solid #E5E5E5;
            color: #E5E5E5;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
            left: 15px;
        }

        .weui-uploader__input-box:before{
            display: none;
        }
        .weui-uploader__input-box:after{
            display: none;
        }
       .weui-label{
            font-weight: 400;
           margin-bottom: 0px;
        }

        .toolbar-inner h1{
            margin-top: 0px;
            margin-bottom: 0px;
            margin-block-end: 0px;
            margin-block-start: 0px;
        }

        .weui-check_label {
            font-weight:400;
        }

        .toolbar .picker-button {
            color: #2e6da4 ;
        }

        .weui-cells_checkbox .weui-check:checked + .weui-icon-checked:before {
            color: #2e6da4;
        }

        .picker-calendar-day.picker-calendar-day-selected span {
            background: #2e6da4;
        }

        i.icon.icon-next {
            background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2015%2015'%3E%3Cg%3E%3Cpath%20fill%3D'%232e6da4'%20d%3D'M1%2C1.6l11.8%2C5.8L1%2C13.4V1.6%20M0%2C0v15l15-7.6L0%2C0L0%2C0z'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E");
        }
        i.icon.icon-prev {
            background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2015%2015'%3E%3Cg%3E%3Cpath%20fill%3D'%232e6da4'%20d%3D'M14%2C1.6v11.8L2.2%2C7.6L14%2C1.6%20M15%2C0L0%2C7.6L15%2C15V0L15%2C0z'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E");
        }
    </style>
</head>
<body>

<form id="reservationForm" onsubmit="return false;" method="post">
    <div class = "block-title" style="display: table; width: 100%;  text-align: left;height: 40px;">
        <div  style="color:#999999;font-size: 16px;display: table-cell; vertical-align: middle;padding-left: 15px;">
            基本信息
        </div>
    </div>
    <div class="weui-cells weui-cells_form " style="margin-top: 0px;">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">预约单号</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="reservationno" name="reservationno" type="text" readonly="readonly" value="">
            </div>
            <div id='qrCode' style="width:40px;height: 40px;background: no-repeat center center;background-size: cover;display: table-cell; text-align: right; padding-right: 20px; vertical-align: middle;">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">接待部门</label></div>
            <div class="weui-cell__bd input-group">
                <input type="hidden" name="deptno" id="deptno" value="" />
                <input class="weui-input" id="deptname" name="deptname" type="text" placeholder="请选择接待部门">
                <div class="input-group-btn" style="width:1px;">
                    <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
                </div>
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">接待人</label></div>
            <div class="weui-cell__bd input-group">
                <input type="hidden" size="16" name="employeenoReception" id="employeenoReception" value="" />
                <input class="weui-input" id="employeenameReception" name="employeenameReception" type="text" placeholder="请选择接待人">
                <div class="input-group-btn" style="width:1px;">
                    <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="employeenoPhone" name="employeenoPhone" type="number">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="forecastVisitingTime" class="weui-label">来访日期</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="forecastVisitingTime" id="forecastVisitingTime" value="" placeholder="年-月-日">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="forecastDepartureTime" class="weui-label">出园日期</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="forecastDepartureTime" id="forecastDepartureTime" value="" placeholder="年-月-日">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">受访区域</label></div>
            <div class="weui-cell__bd">
                <input type="hidden" class="inputClass" id="districtName" name="districtName" value="">
                <input type="hidden" class="inputClass" id="districtno" name="districtno" value="">
                <input class="weui-input" id="districtnoIn" name="districtnoIn" type="text" placeholder="请选择受访区域">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">访客单位</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="visitorCompany" name="visitorCompany" type="text" placeholder="请输入访客单位">
            </div>
        </div>


        <div class="weui-cell" style="align-items: start">
            <div class="weui-cell__hd"><label class="weui-label">来访事宜</label></div>
            <div class="weui-cell__bd">
                <textarea name="visitingMatters" id="visitingMatters" class="weui-textarea" placeholder="请输入来访事宜" rows="3"></textarea>
            </div>
        </div>


    </div>

    <div class = "block-title" style="display: table; width: 100%;  text-align: left;height: 40px;">
        <div  style="color:#999999;font-size: 16px;display: table-cell; vertical-align: middle;padding-left: 15px;">
            访客信息
        </div>
        <div style="display: table-cell; text-align: right; padding-right: 16px; vertical-align: middle;">
            <button id='addVisitorBtn' class="weui-btn weui-btn_mini weui-btn_primary btn-color-light-blue" style="display:inline-block;vertical-align: middle;padding-left: 10px;padding-right: 10px;"><i class="fa fa-plus"></i>新增</button>
        </div>
    </div>
   <div id="visitorContentDiv" style="min-height: 60px;background-color: #FFFFFF;">
        <div id="noVisitorMsg" class="weui-cell">
            暂无访客信息
        </div>
    </div>

    <div class="weui-btn-area " style="margin-bottom: 20px;">
        <button class="weui-btn weui-btn_primary btn-color-light-blue" id="submitBtn">提交</button>
    </div>

</form>


<script src="${ctx}/static/jqweui/js/jquery-2.1.4.js"></script>
<script src="${ctx}/static/jqweui/js/jquery-weui.js?v=1.3"></script>
<script src="${ctx}/static/handlerbars.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap-suggest.min.js"></script>
<script src="${ctx}/static/jquery.qrcode.min.js"></script>
<script id="visitor-template" type="text/x-handlebars-template">
    <div class="weui-media-box weui-media-box_text visitorPanel">
        <input class="visitor" id="visitor" name="visitor" type="hidden" value="{{visitor}}">
        <input class="idcardno" id="idcardno" name="idcardno" type="hidden" value="{{idcardno}}">
        <input class="carryItems" id="carryItems" name="carryItems" type="hidden" value="{{carryItems}}">
        <input class="visitorPosition" id="visitorPosition" name="visitorPosition" type="hidden" value="{{visitorPosition}}">
        <input class="phone" id="phone" name="phone" type="hidden" value="{{phone}}">
        <input class="photoBase64" id="photoBase64" name="photoBase64" type="hidden" value="">

        <div style="display: table; width: 100%;  text-align: left;">
            <h4 class="weui-media-box__title" style="display: table-cell;font-weight: 400;font-size: 17px;color: #2e6da4">{{visitor}}</h4>
            <div style="display: table-cell; text-align: right; padding-right: 1px; vertical-align: middle;">
                <button id='deleteVisitorBtn' class="weui-btn weui-btn_mini weui-btn_primary btn-color-red" style="display:inline-block;vertical-align: middle;padding-left: 10px;padding-right: 10px;" onclick="deletePanel(this)"><i class="fa fa-trash"></i>删除</button>
            </div>
        </div>

        <div style="display: table; width: 100%;  text-align: left;">
            <p class="weui-media-box__desc" style="margin-top: 8px;">身份证号:{{idcardno}}</p>
            <p class="weui-media-box__desc" style="margin-top: 8px;">职务:{{visitorPosition}}</p>
            <p class="weui-media-box__desc" style="margin-top: 8px;">手机号:{{phone}}</p>
            <p class="weui-media-box__desc" style="margin-top: 8px;">携带物品:{{carryItems}}</p>
            <div style="display: table-cell; text-align: right; padding-right: 5px; vertical-align: middle;">
                <div class="weui-uploader__input-box weui-uploader__file" style="border:1px dashed #D9D9D9;width:60px;height: 60px;float: right;margin-top: 9px;margin-left: 9px;margin-right: 0px;background-image:url(${ctx}/static/jqweui/images/camera2.jpg)">
                    <input id="uploaderInput" onchange="chooseImg(event,this)" class="weui-uploader__input" type="file" accept="image/*" multiple="">
                </div>
            </div>
        </div>

    </div>
</script>
<script type="text/javascript">


    function getNewReservationNo(){
        $.ajax({
            url : "${ctx}/reservation/getNewReservationNo",
            type : "GET",
            dataType:'json',
            success : function(data) {
                if (data.success) {

                    $("#reservationno").val(data.data);

                    $("#qrCode").html("");
                    $("#qrCode").qrcode({
                        render: "canvas", //也可以替换为table
                        width: 40,
                        height: 40,
                        text: data.data
                    });
                } else {
                    alert(data.message);
                }
            },
            error : function(data) {

            }
        });
    }

    function refreshReservationNo(){
        $.ajax({
            url : "${ctx}/reservation/getNewReservationNo",
            type : "GET",
            dataType:'json',
            success : function(data) {
                if (data.success) {

                    $("#reservationno").val(data.data);

                    $("#qrCode").html("");
                    $("#qrCode").qrcode({
                        render: "canvas", //也可以替换为table
                        width: 40,
                        height: 40,
                        text: data.data
                    });

                    $("#qrCodeDialog").html("");
                    $("#qrCodeDialog").qrcode({
                        render: "canvas", //也可以替换为table
                        width: 200,
                        height: 200,
                        text: $("#reservationno").val()
                    });
                } else {
                    alert(data.message);
                }
            },
            error : function(data) {

            }
        });
    }

    $(function () {
        getNewReservationNo();
        $.ajax({
            url : "${ctx}/reservation/getDistricts",
            type : "POST",
            dataType:'json',
            success : function(data) {
                if (data.success) {
                    var dataArray = [];
                    var i;
                    var len = data.data.length;
                    for (i = 0; i < len; i++) {
                        dataArray.push({
                            "title": data.data[i].districtName,
                            "value": data.data[i].districtno
                        });
                    }
                    $("#districtnoIn").select({
                        title: "受访区域",
                        multi: true,
                        min: 0,
                        items: dataArray,
                        beforeClose: function(values, titles) {
                            $("#districtno").val(values);
                            $("#districtName").val(titles);
                            return true;
                        },
                        onChange: function(d) {
                            console.log(this, d);
                        },
                        onClose: function (d) {
                            console.log('close')
                        }
                    });
                } else {
                    alert(data.message);
                }
            },
            error : function(data) {

            }
        });

    });

    var allowTypes = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'];
    var maxSize = 4096 * 2048;
    // 图片最大宽度
    var maxWidth = 300;
    // 最大上传图片数量
    var maxCount = 1;

    // 抓取模板数据
    var theTemplateScript = $("#visitor-template").html();
    // 编译模板
    var theTemplate = Handlebars.compile(theTemplateScript);

    function deletePanel(obj){
        var $this = $(obj);
        $this.parent().parent().parent().remove();

        var length = $(".visitorPanel").length;
        if(length==0){
            $("#noVisitorMsg").show();
        }
    }

    var deptname = $("#deptname").bsSuggest({
            indexId: 0, //data.value 的第几个数据，作为input输入框的内容
            indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: false, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            effectiveFields:["deptno","deptname"],
            effectiveFieldsAlias:{deptno: "编号",deptname:"名称"},
            showHeader: true,
            url: '${ctx}/dept/searchDeptByKeyword?keywords=', /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
            processData: function(json){// url 获取数据时，对数据的处理，作为 getData 的回调函数
                var i, len, data = {value: []};
                if(!json || json.length == 0) {
                        return false;
                    }
                len = json.length;
                for (i = 0; i < len; i++) {
                        data.value.push({
                                "deptno": json[i].deptno,
                                "deptname": json[i].deptname
                        });
                    }
                console.log(data);
                return data;
            }
    }).on('onSetSelectValue', function (e, selectedData, selectedRawData) {
        console.log('onSetSelectValue: ', e.target.value, selectedData, selectedRawData);
        $("#deptno").val(selectedData.id);
    });

    var employeenameReception = $("#employeenameReception").bsSuggest({
        indexId: 0, //data.value 的第几个数据，作为input输入框的内容
        indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
        allowNoKeyword: false, //是否允许无关键字时请求数据
        multiWord: false, //以分隔符号分割的多关键字支持
        separator: ",", //多关键字支持时的分隔符，默认为空格
        getDataMethod: "url", //获取数据的方式，总是从 URL 获取
        effectiveFields:["employeeno","employeename"],
        effectiveFieldsAlias:{employeeno: "工号",employeename:"姓名"},
        showHeader: true,
        url: '${ctx}/employee/getEmployeeByNameDim?keywords=', /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
        processData: function(json){// url 获取数据时，对数据的处理，作为 getData 的回调函数
            var i, len, data = {value: []};
            if(!json || json.length == 0) {
                return false;
            }
            len = json.length;
            for (i = 0; i < len; i++) {
                data.value.push({
                    "employeeno": json[i].employeeno,
                    "employeename": json[i].employeename
                });
            }
            console.log(data);
            return data;
        }
    }).on('onSetSelectValue', function (e, selectedData, selectedRawData) {
        console.log('onSetSelectValue: ', e.target.value, selectedData, selectedRawData);
        $("#employeenoReception").val(selectedData.id);
    });


    function chooseImg(event,obj){
        var $thisObj = $(obj).parent();
        var files = event.target.files;
        if (files.length === 0) {
            return;
        }
        var file = files[0];
        var reader = new FileReader();
        if (allowTypes.indexOf(file.type) === -1) {
            $.alert("该类型不允许上传！", "警告！");
            return;
        }

        if (file.size > maxSize) {
            $.alert("图片太大，不允许上传", "警告！");
            return;
        }

        reader.readAsDataURL(file);
        reader.onload = function (e) {
            var img = new Image();
            img.src = e.target.result;
            img.onload = function () {
                // 不要超出最大宽度
                var w = Math.min(maxWidth, img.width);
                // 高度按比例计算
                var h = img.height * (w / img.width);
                var canvas = document.createElement('canvas');
                var ctx = canvas.getContext('2d');
                // 设置 canvas 的宽度和高度
                canvas.width = w;
                canvas.height = h;
                ctx.drawImage(img, 0, 0, w, h);

                var base64 = canvas.toDataURL('image/jpeg',0.8);
                // 插入到预览区
                //console.log(base64);
                $thisObj.attr("style","float: right;margin-top: 9px;margin-left: 9px;margin-right: 0px;background-image:url('" + base64 +" ')");

                var base64Data = base64.substr(base64.indexOf(",")+1);
                console.log(base64Data);
                $thisObj.parent().parent().parent().find('.photoBase64').val(base64Data);
            };


        };

    }

    function AddDays(date,days){
        var nd = new Date(date);
        nd = nd.valueOf();
        nd = nd + days * 24 * 60 * 60 * 1000;
        nd = new Date(nd);
        var y = nd.getFullYear();
        var m = nd.getMonth()+1;
        var d = nd.getDate();
        if(m <= 9) m = "0"+m;
        if(d <= 9) d = "0"+d;
        var cdate = y+"-"+m+"-"+d;
        return cdate;
    }

    $("#forecastVisitingTime").calendar({
        dateFormat:"yyyy-mm-dd",
        onChange: function (p, values, displayValues) {
            $("#forecastDepartureTime").val(AddDays(values,6));
        }
    });

    $("#forecastDepartureTime").calendar({
        dateFormat:"yyyy-mm-dd",
        value: $("#forecastDepartureTime").val(),
        onChange: function (p, values, displayValues) {
        }
    });

    $("#qrCode").on("click",function(){
        $.modal({
            title: "二维码",
            text: "<div id='qrCodeDialog' style='width:200px;height: 200px;margin: 10px auto'></div>",
            buttons: [
                { text: "关闭", className: "default"},
                { text: "刷新", onClick: function(){

                    },validate:function () {
                        refreshReservationNo();
                        return false;
                    } }
            ],
        },function () {
            $("#qrCodeDialog").qrcode({
                render: "canvas", //也可以替换为table
                width: 200,
                height: 200,
                text: $("#reservationno").val()
            });

        });
    });

    $("#addVisitorBtn").on("click",function(){
        $.modal({
            title: "新增访客",
            text: "<input class='weui-input weui-prompt-input' style='color: #0D0D0D' id='mVisitor' name='mVisitor' type='text' placeholder='访客姓名'>" +
                "<input class='weui-input weui-prompt-input' style='color: #0D0D0D' id='mIdcardno' name='mIdcardno' type='text' placeholder='身份证号'>" +
                "<input class='weui-input weui-prompt-input' style='color: #0D0D0D' id='mPhone' name='mPhone' type='text' placeholder='手机号'>" +
                "<input class='weui-input weui-prompt-input' style='color: #0D0D0D' id='mVisitorposition' name='mVisitorposition' type='text' placeholder='访客所属部门职务'>" +
                "<input class='weui-input weui-prompt-input' style='color: #0D0D0D;margin-bottom: 15px;' id='mCarryitems' name='mCarryitems' type='text' placeholder='携带物品'>",
            buttons: [
                { text: "取消", className: "default"},
                { text: "确定", onClick: function(){
                        
                        var visitor = $("#mVisitor").val();
                        var idcardno = $("#mIdcardno").val();
                        var phone = $("#mPhone").val();
                        var visitorPosition = $("#mVisitorposition").val();
                        var carryItems = $("#mCarryitems").val();
                        
                        $("#noVisitorMsg").hide();
                        var context={
                            "visitor": visitor,
                            "idcardno": idcardno,
                            "phone": phone,
                            "visitorPosition": visitorPosition,
                            "carryItems": carryItems,

                        };
                        var theCompiledHtml = theTemplate(context);

                        $("#visitorContentDiv").append(theCompiledHtml);

                },validate:function () {
                        //校验新增访客信息是否完整
                        var visitor = $("#mVisitor").val();
                        var idcardno = $("#mIdcardno").val();
                        var phone = $("#mPhone").val();
                        var visitorPosition = $("#mVisitorposition").val();
                        var carryItems = $("#mCarryitems").val();
                        //校验新增访客信息是否完整
                        if(visitor.trim()==""){
                            $.toptip("请输入访客姓名","error");
                            return false;
                        }
                        if(idcardno.trim()==""){
                            $.toptip("请输入身份证号","error");
                            return false;
                        }
                        if(phone.trim()==""){
                            $.toptip("请输入手机号","error");
                            return false;
                        }
                        if(visitorPosition.trim()==""){
                            $.toptip("请输访客所属部门职务","error");
                            return false;
                        }
                        if(carryItems.trim()==""){
                            $.toptip("携带物品","error");
                            return false;
                        }

                        return true;
                    } },
            ],
        },function () {
        });
    });

    $("#submitBtn").on("click",function(){
    
        //校验表单信息是否完整
        var deptno=$("#deptno").val();
        if(deptno.trim()==""){
            $.toptip("请选择接待部门","error");
            $("#deptname").focus();
            return;
        }
        
        var employeenoReception=$("#employeenoReception").val();
        if(employeenoReception.trim()==""){
            $.toptip("请选择接待人","error");
            $("#employeenameReception").focus();
            return;
        }
        
        var employeenoPhone=$("#employeenoPhone").val();
        if(employeenoPhone.trim().length<11){
            $.toptip("请输入手机号,并且为11位","error");
            $("#employeenoPhone").focus();
            return;
        }
        
        var forecastVisitingTime=$("#forecastVisitingTime").val();
        if(forecastVisitingTime.trim()==""){
            $.toptip("请选择来访日期","error");
            $("#forecastVisitingTime").focus();
            return;
        }
        
        var forecastDepartureTime=$("#forecastDepartureTime").val();
        if(forecastDepartureTime.trim()==""){
            $.toptip("请选择出园日期","error");
            $("#forecastDepartureTime").focus();
            return;
        }
        
        var districtno=$("#districtno").val();
        if(districtno.trim()==""){
            $.toptip("请选择受访区域","error");
            $("#districtnoIn").focus();
            return;
        }
        
        var visitorCompany=$("#visitorCompany").val();
        if(visitorCompany.trim()==""){
            $.toptip("请输入访客单位","error");
            $("#visitorCompany").focus();
            return;
        }
    
        var visitingMatters=$("#visitingMatters").val();
        if(visitingMatters.trim()==""){
            $.toptip("请输入来访事宜","error");
            $("#visitingMatters").focus();
            return;
        }
        
        
        //子表重命名
        $('.visitorPanel').each(function (index) {
            var $this = $(this);
            $this.find('.visitor').attr('id','reservationList['+index+'].visitor');
            $this.find('.visitor').attr('name','reservationList['+index+'].visitor');

            $this.find('.idcardno').attr('id','reservationList['+index+'].idcardno');
            $this.find('.idcardno').attr('name','reservationList['+index+'].idcardno');

            $this.find('.phone').attr('id','reservationList['+index+'].phone');
            $this.find('.phone').attr('name','reservationList['+index+'].phone');

            $this.find('.visitorPosition').attr('id','reservationList['+index+'].visitorPosition');
            $this.find('.visitorPosition').attr('name','reservationList['+index+'].visitorPosition');

            $this.find('.carryItems').attr('id','reservationList['+index+'].carryItems');
            $this.find('.carryItems').attr('name','reservationList['+index+'].carryItems');

            $this.find('.photoBase64').attr('id','reservationList['+index+'].photoBase64');
            $this.find('.photoBase64').attr('name','reservationList['+index+'].photoBase64');
        });


        $.ajax({
            url : "${ctx}/reservation/saveNew",
            type : "POST",
            dataType:'json',
            data:$('#reservationForm').serialize(),
            success : function(data) {
                if (data.success) {
                    window.history.go(-1);
                } else {
                    alert(data.message);
                }
            },
            error : function(data) {

            }
        });
    });


</script>
</body>
</html>